#include "IndexBuffer.h"

IndexBuffer::IndexBuffer()
{
    mType = kXBufferObjectTypeIndexBuffer;
    mIndexes = nullptr;
    mIndexCount = 0;
    mCurrentIndex = 0;
}

IndexBuffer::~IndexBuffer()
{
    if (mIndexes)
    {
        delete[] mIndexes;
    }
}

void IndexBuffer::SetSize(int count)
{
    mIndexCount = count;
    if (mIndexes)
    {
        delete[] mIndexes;
    }
    mIndexes = new unsigned int[count];

    XBufferObject::OnSetSize();
}

int IndexBuffer::GetSize()
{
    return mIndexCount * sizeof(unsigned int);
}

void IndexBuffer::AppendIndex(int index)
{
    mIndexes[mCurrentIndex++] = index;
}

void IndexBuffer::SubmitData()
{
    XBufferObject::SubmitData(mIndexes, GetSize());
}
